package com.cnap.multiclouldmgmt.vm.web;

import com.cnap.multiclouldmgmt.MulticlouldmgmtApplicationTests;
import com.cnap.multiclouldmgmt.model.CommonResult;
import com.cnap.multiclouldmgmt.vm.service.VMScale;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;

public class VMScaleWebTest extends MulticlouldmgmtApplicationTests {
    @InjectMocks
    private VMScaleWeb vmScaleWeb;

    @Mock
    VMScale vmScale;

    @Test
    public void addVmPolicyTest() throws InterruptedException {
        CommonResult<String> result = new CommonResult<>();
        result.setCode(200);
        result.setMessage("新增成功");
        result.setData("");
        Mockito.when(vmScale.addScalePolicy(Mockito.any())).thenReturn(result);
        CommonResult<String> stringCommonResult = vmScaleWeb.addVmPolicy("100");
        Assertions.assertEquals(stringCommonResult.getCode(),200);
    }

    @Test
    public void deleteVmPolicyTest() throws InterruptedException {
        CommonResult<String> result = new CommonResult<>();
        result.setCode(200);
        result.setMessage("删除成功");
        result.setData("");
        Mockito.when(vmScale.deleteScalePolicy(Mockito.any())).thenReturn(result);
        CommonResult<String> stringCommonResult = vmScaleWeb.deleteVmPolicy("100");
        Assertions.assertEquals(stringCommonResult.getMessage(),"删除成功");
    }

    @Test
    public void updateVmPolicyTest() throws InterruptedException {
        CommonResult<String> result = new CommonResult<>();
        result.setCode(200);
        result.setMessage("修改成功");
        result.setData("");
        Mockito.when(vmScale.updateScalePolicy(Mockito.any())).thenReturn(result);
        CommonResult<String> stringCommonResult = vmScaleWeb.updateVmPolicy("100");
        Assertions.assertEquals(stringCommonResult.getMessage(),"修改成功");
    }
}
